package www.rlicker.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.rlicker.dao.IFeedbackClassDao;
import www.rlicker.model.FeedbackClass;
import www.rlicker.mybatis.Criteria;
import www.rlicker.service.IFeedbackClassService;
import www.rlicker.utils.MessageConstant;
import www.rlicker.utils.TranslateToMap;


@Service
public class FeedbackClassServiceImpl implements IFeedbackClassService{


	public List<Map<String, Object>>  queryPage (Criteria<FeedbackClass> param){
		//PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<FeedbackClass> list = feedbackClassRepository.queryPage(param);
		List<Map<String,Object>> map = TranslateToMap.convertListBean2ListMap(list,FeedbackClass.class);
	return map;  }

	public Integer queryPageCount (Criteria<FeedbackClass> param){
		return (Integer) feedbackClassRepository.queryPageCount(param);
	}

	public FeedbackClass  queryEntity (Long id ){
		return feedbackClassRepository.queryEntity(id);
	}

	public String deleteAll (String id){
		List<Long> list = Arrays.asList(id.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
		int result = feedbackClassRepository.deleteAll(list);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_3;
			}
			return null;
	}

	public String insert(FeedbackClass record ){
		int result = feedbackClassRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_4;
			}
			return null;
	}

	public String update (Criteria<FeedbackClass> param){
		int result = feedbackClassRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}

	@Override
	public FeedbackClass queryByName(String name) {
		return feedbackClassRepository.queryByName(name);
	}
	
	@Override
	public List<FeedbackClass> queryPageList() {
		return feedbackClassRepository.queryPage(null);
	}
	
	@Resource
	private IFeedbackClassDao feedbackClassRepository;

}